﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Customer_Profile.Admin
{
    public partial class UserManage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // 在此处放置用户代码以初始化页面
            if (!Page.IsPostBack)
            {
                TreeNode rootNode = new TreeNode();
                rootNode.Text = "User";
                rootNode.Value = "-1";
                rootNode.Expanded = true;
                rootNode.ShowCheckBox = true;
                treeMenu.Nodes.Add(rootNode);

                AddTree(0, rootNode);

                //记录用户操作日志
                //CVOC.Comm.WriteSystemLog(Session["SS_USER_ID"].ToString(), Utility.ReplaceChar(Utility.ReplaceQuote(Request["menu_idx"].ToString()), true), "01", Page.Request.UserHostAddress, Page.Request.Path, "自动加载“菜单管理”信息");
            }
        }

        public void AddTree(int ParentID, TreeNode pNode)
        {

            DataSet ds = UserDao.GetAllUserInfo(ParentID);

            DataView dvtree = ds.Tables[0].DefaultView;
            foreach (DataRowView Row in dvtree)
            {
                TreeNode Node = new TreeNode();
                if (pNode == null)
                {
                    #region
                    Node.Text = Row["User_loginID"].ToString();
                    Node.Value = Row["User_Id"].ToString();

                    Node.ShowCheckBox = true;
                    if (Row["used_yn"].ToString() == "True")
                        Node.Checked = true;
                    Node.Expanded = true;

                    treeMenu.Nodes.Add(Node);
                    AddTree(Convert.ToInt32(Row["User_Id"].ToString()), Node);
                    #endregion
                }
                else
                {
                    #region
                    Node.Text = Row["User_loginID"].ToString();
                    Node.Value = Row["User_Id"].ToString();
                    Node.ShowCheckBox = true;
                    if (Row["Used_YN"].ToString() == "true")
                        Node.Checked = true;
                    pNode.ChildNodes.Add(Node);
                    //pNode.Nodes.Add(Node);
                    AddTree(Convert.ToInt32(Row["User_Id"].ToString()), Node);
                    #endregion
                }
            }
        }

        protected void ibtnAdd_ServerClick(object sender, EventArgs e)
        {
            if (treeMenu.CheckedNodes.Count == 0)
            {
                KVB.Common.JavaScript.ViewAlertMsg("you must select!");
                return;
            }
            TreeNode node = treeMenu.CheckedNodes[0];
            string selectId = node.Value;
            string selectName = node.Text;

            Response.Redirect("UserAdd.aspx?id=" + selectId, true);
            //Response.Redirect("MenuAdd.aspx?id=" + selectId + "&menu_idx=" + Utility.ReplaceChar(Utility.ReplaceQuote(Request["menu_idx"].ToString()), true));
        }

        protected void ibtnModify_ServerClick(object sender, EventArgs e)
        {
            if (treeMenu.CheckedNodes.Count == 0)
            {
                KVB.Common.JavaScript.ViewAlertMsg("you must select!");
                return;
            }
            TreeNode node = treeMenu.CheckedNodes[0];
            string selectId = node.Value;
            if (selectId != "-1")
            {
                Response.Redirect("UserModify.aspx?id=" + selectId, true);
            }
            else
            {
                Response.Write("<script language=javascript>alert('You Must Select!');</script>");
            }
        }
    }
}
